##
##    This file is part of Metrix.
##
##    Metrix is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    Metrix is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with Metrix.  If not, see <http://www.gnu.org/licenses/>.
##

class RecursosController < ApplicationController

  layout "recursos"
  active_scaffold :recursos do |config|
    config.label = "Recursos"
    config.columns = [:apellido, :nombre, :tipo, :seniority]
	## si son iguales la lista de arriba y la de abajo, la list.columns es opcional
    config.list.columns = [:apellido, :nombre, :tipo, :seniority]
    list.sorting = {:apellido => :asc}


	## NO USAR ESTO SI SE USA LO QUE APARECE EN recursos_helper EN seniority_form_column Y tipo_form_column
	#config.columns[:tipo].ui_type = :select
	#config.columns[:seniority].ui_type = :select

	## Busqueda ajax
	config.actions.swap :search, :live_search

	## Castellano
	config.actions = [:show, :update, :delete, :create, :list, :live_search]
	config.show.link.label = 'Ver'
	config.update.link.label = 'Modificar'
	config.delete.link.label = 'Borrar'
	config.create.link.label = 'Crear'
	config.live_search.link.label = 'Buscar'

  end

	def destroy
		begin
			super
		rescue ActiveRecord::ReferentialIntegrityProtectionError
			flash[:notice] = 'No se pueden borrar recursos que tengan incidentes asociados'
			redirect_to :controller=> 'recursos', :action => 'index'
		end
	end

#	def destroy
#	  begin
#	    Recurso.find(params[:id]).destroy
#	    rescue ActiveRecord::ReferentialIntegrityProtectionError => e
#	    flash[:notice] = e
#	  end
#	  redirect_to :action => 'list'
#	end

end
